#include "Reactor.hpp"
#include "Listener.hpp"
#include "PackageParse.hpp"
#include <memory>

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage:\r\n\t" << argv[0] << " [port]\n"; 
        return 1;
    }

    std::unique_ptr<Reactor> react = std::make_unique<Reactor>();

    HandleConnection hc(std::bind(&PackageParse::Parse, std::placeholders::_1));

    uint16_t port = std::stoi(argv[1]);
    Listener listener(port, hc);

    
    react->AddConnection(listener.GetListenSockfd(), EPOLLIN | EPOLLET, std::bind(&Listener::Accept, &listener, std::placeholders::_1), nullptr, nullptr);

    react->Dispatcher();
    
    return 0;
}